<?php
    $current_url_params = [];
    if (!$pagination->isCurrentFirstPage()) {
        $current_url_params = [
            'page' => $pagination->currentPage(),
        ];
    }

    $this->layout('reading.phtml', [
        'title' => _('Bookmarks'),
        'canonical' => url_full('bookmarks', $current_url_params),
        'current_tab' => 'reading',
        'current_page' => 'bookmarks',
        'reset_back_options' => true,
    ]);
?>

<div class="section__title">
    <h1><?= protect($collection->name()) ?></h1>
</div>

<p class="section__intro">
    <?= _('Place here the links you want to consult later on.') ?>
</p>

<?php if ($pagination->numberElements() > 0): ?>
    <div class="collection__number-links">
        <?= _nf('%s link', '%s links', $pagination->numberElements(), format_number($pagination->numberElements())) ?>
    </div>
<?php endif; ?>

<div class="cards">
    <div class="card">
        <button
            class="card__button card__button--link"
            data-controller="modal-opener"
            data-action="modal-opener#fetch"
            data-modal-opener-href-value="<?= url('new collection link', ['id' => $collection->id, 'from' => url('bookmarks', $current_url_params)]) ?>"
            aria-haspopup="dialog"
            aria-controls="modal"
        >
            <?= icon('plus-circle') ?><br />
            <?= _('Add a link') ?>
        </button>
    </div>

    <?php foreach ($links as $link): ?>
        <?= $this->include('links/_link.phtml', [
            'link' => $link,
            'from' => \Minz\Url::for('bookmarks', $current_url_params),
            'display_source' => $link->source_type !== 'bookmarks',
            'display_notes' => true,
            'display_edit' => true,
            'display_repair' => true,
            'display_delete' => true,
            'display_mark_as_read' => true,
        ]); ?>
    <?php endforeach; ?>

    <?php for ($i = 0; $i < (3 - ((count($links) + 1) % 3)); $i++): ?>
        <div class="card card--shadow no-mobile"></div>
    <?php endfor; ?>
</div>

<?= $this->include('_pagination.phtml', ['pagination' => $pagination, 'url' => url('bookmarks')]) ?>

<img
    class="illustration illustration--centered"
    alt=""
    src="<?= url_static('illustrations/working-late.svg') ?>"
    height="250"
/>
